package com.tutu.controller.backend;

import com.tutu.common.DataTableFactory;
import com.tutu.controller.common.CommonController;
import com.tutu.service.VerifyInfoService;
import com.tutu.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 验证消息管理
 */
@Controller
@RequestMapping(value = "backend/verifyInfo")
public class VerifyInfoController extends CommonController {

    public static Map<String, Map<String, Object>> tempVerifyInfoMap = new HashMap<>();

    @Autowired
    VerifyInfoService verifyInfoService;

    @RequestMapping(value = "/index")
    public String index() {
        return "backend/verifyInfo/list";
    }

    @RequestMapping(value = "/child/index")
    public String childIndex(Model model, String accessToken, Integer pageNum) {
        model.addAttribute("verifyInfo", tempVerifyInfoMap.get(accessToken));
        model.addAttribute("pageNum", pageNum);

        return "backend/verifyInfo/childList";
    }

    @RequestMapping("/list")
    public void list(HttpServletResponse response, Integer status, String keyWord, Integer draw, Integer start, Integer length) {
        int pageNum = getPageNum(start, length);

        Map<String, Object> result = DataTableFactory.fitting(draw, verifyInfoService.pageByParams(status, keyWord, pageNum, length));

        WebUtil.printJson(response, result);
    }

    @RequestMapping("/save")
    @ResponseBody
    public Map<String, Object> saveInfo(HttpServletRequest request, Integer id, String title, String endTime, Integer status) {
        return verifyInfoService.saveInfo(request, id, title, endTime, status);
    }

    @RequestMapping("/del")
    @ResponseBody
    public Map<String, Object> delete(HttpServletRequest request, Integer id) {
        return verifyInfoService.delInfo(request, id);
    }

    @RequestMapping("/updateDeviceInfo")
    @ResponseBody
    public Map<String, Object> updateDeviceInfo(HttpServletRequest request, Integer id, String content) {
        return verifyInfoService.updateDeviceInfo(request, id, content);
    }
}
